// 判断时候在Iframe框架内,在则刷新父页面
if (self != top) {
    parent.location.reload(true);
    if (!!(window.attachEvent && !window.opera)) {
        document.execCommand("stop");
    } else {
        window.stop();
    }
}

$(function () {
	//判断cookie是否开启
	var time = new Date();
	time.setSeconds(time.getSeconds() + 60);
	document.cookie = "cookiecheck=1; expires=" + time.toGMTString();
	var isCookieEnabled = document.cookie.indexOf("cookiecheck=") != -1;
	if(!isCookieEnabled){
		$("#nerror").attr("style","display:block;");//显示div
    }
	
    $("#loginUserName").val($.cookie('username'));

    //验证
    function loginValid() {
        if(!$("#loginUserName").val().trim() || !$("#loginPassword").val().trim()){
            return true;
        }
        return false;
    }
    //回车登陆
    document.onkeydown=function(event){
        var e = event || window.event || arguments.callee.caller.arguments[0];
        if((e && e.keyCode==13)){ // enter 键
            if (loginValid()){
                layer.msg('用户名或密码不能有空！',{icon: 2});
                return;
            }
            if(!isCookieEnabled){
        		layer.msg('无法登录，请开启浏览器cookies！',{icon: 2});
        		return;
        	}
            login();
        }
    };

    $("#loginBtn").click(function () {
        if(loginValid()) {
            layer.msg('用户名或密码不能有空！',{icon: 2});
            return;
        }
        if(!isCookieEnabled){
    		layer.msg('无法登录，请开启浏览器cookies！',{icon: 2});
    		return;
    	}
        login();
    });

    function login() {
        $.ajax({
            url: "user/login.htm",
            cache: true,
            type: "post",
            data: /*$("#loginform").serializeArray(),*/
            {username: $("#loginUserName").val(),
                   password: $("#loginPassword").val(),
                   isRememberUserName : $("#isRememberUserName").val()},
            dataType: "json",
            success: function (result) {
                var isChecked = $("#isRememberUserName").is(':checked');
                if (isChecked){
                    $.cookie('username', $("#loginUserName").val(),{ expires: 7 });
                }
                if (result.status != 0) {
                    layer.msg(result.message, {icon: 2});
                    return;
                }
            	
            	if(result.success == 'true'){
            		console.log(result.message);
            	}
                location.href = "index.htm";
            }
        });
    }

});


 
